#f21010631徐唯嘉h
import cv2
import numpy as np

from 显示图片  import my_img_show
#均值滤波
img_0 = cv2.imread("zaosheng.jpeg")

img_1 = cv2.blur(img_0,(3,3))
img_stack = np.hstack([img_0,img_1])
my_img_show(img_stack)
cv2.waitKey(0)

#高斯滤波
img=cv2.imread('zaosheng.jpeg')
cv2.imshow('img',img)
img2=cv2.GaussianBlur(img,(5,5),0,0)			#可调整卷积核大小以查看不同效果
cv2.imshow('imgBlur',img2)
cv2.waitKey(0)

#方框滤波
img=cv2.imread('zaosheng.jpeg')
cv2.imshow('img',img)
img2=cv2.boxFilter(img,-1,(3,3),normalize=False) 	  #可调整卷积核大小以查看不同效果
cv2.imshow('imgBlur',img2)
cv2.waitKey(0)

#中值滤波
img=cv2.imread('zaosheng.jpeg')
cv2.imshow('img',img)
img2=cv2.medianBlur(img,21)		#可调整卷积核大小以查看不同效果
cv2.imshow('imgBlur',img2)
cv2.waitKey(0)

#双边滤波
img=cv2.imread('zaosheng.jpeg')
cv2.imshow('img',img)
img2=cv2.bilateralFilter(img,20,100,100)		#可调整参数以查看不同效果
cv2.imshow('imgBlur',img2)
cv2.waitKey(0)

#2D卷积
img=cv2.imread('zaosheng.jpeg')
k1=np.array([[3,3,3,3,3],[3,9,9,9,3],[3,11,12,13,3],[3,8,8,8,3],
             [3,3,3,3,3],])/25		#自定义卷积核1
k2=np.ones((5,5),np.float32)/25		#自定义卷积核2
img2=cv2.filter2D(img,-1,k1)
cv2.imshow('imgK1',img2)
img2=cv2.filter2D(img,-1,k2)
cv2.imshow('imgK2',img2)
cv2.waitKey(0)